<template>
  <div>
    <el-dialog
      title="异常处理"
      :visible.sync="dialogVisible"
      width="750px"
      :close-on-click-modal="false"
      append-to-body
      @close="close"
    >
      <el-form
        ref="form"
        v-loading="loading"
        :model="form"
        :rules="rules"
        label-width="100px"
        class="demo-ruleForm"
      >
        <ul v-if="errorArr&&errorArr.length>0" type="danger" class="error-content">
          <li>订单异常</li>
          <li v-for="(item,index) in errorArr" :key="item.itemId">{{ index+1 }}. {{ item.remark }}</li>
        </ul>
        <!-- <el-form-item v-if="errorArr&&errorArr.length>0" label="订单异常：">
          <ul type="danger" class="error-tips-container">
            <li v-for="(item,index) in errorArr" :key="item.itemId">{{index+1}}. {{item.remark}}</li>
          </ul>
        </el-form-item>-->
        <el-form-item label="处理备注：" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 6}"
            maxlength="200"
            show-word-limit
          />
        </el-form-item>
      </el-form>
      <!-- 按钮 -->
      <div class="btn-group">
        <el-button type="primary" :disabled="loading" round size="small" @click="submit(1)">已处理</el-button>
        <el-button type="success" :disabled="loading" round size="small" @click="submit(2)">忽略异常</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { confirmOrderError } from '@/views/wxaMallModule/api/order'
export default {
  data() {
    return {
      // 校验字段
      rules: {},
      // 配置
      resolve: null,
      reject: null,
      // 状态
      dialogVisible: null,
      loading: false,
      // 数据
      detail: null,
      errorArr: null,
      form: {
        remark: null
      }
    }
  },
  methods: {
    /**
       * 弹框相关
       */
    open({ detail, errorArr }) {
      this.detail = detail
      this.errorArr = errorArr
      this.show()
      return new Promise((resolve, reject) => {
        this.resolve = resolve
        this.reject = reject
      })
    },

    show() {
      this.dialogVisible = true
    },

    close() {
      this.form = { remark: null }
      this.loading = false
    },

    hide() {
      this.resolve = null
      this.reject = null
      this.dialogVisible = false
    },

    /**
       * 数据组
       */

    /**
       * 按钮组
       */
    // 确 定
    submit(status) {
      const params = {
        exceptionId: this.detail.orderException.id,
        orderNo: this.detail.orderNo,
        remark: this.form.remark,
        status: status
      }
      this.loading = true
      confirmOrderError(params)
        .then((res) => {
          this.$notify({
            title: '成功',
            message: '处理成功',
            type: 'success',
            duration: 2000,
            offset: 40
          })
          this.resolve && this.resolve()
          this.hide()
        })
        .catch((err) => {})
        .finally(() => {
          this.loading = false
        })
    }

    /**
       * 状态组
       */

    /**
       * 方法组
       */
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
  .error-content {
    margin-bottom: 10px;
    padding: 5px 10px;
    font-size: 12px;
    line-height: 1.4;
    color: #409eff;
    border: 1px solid #d9ecff;
    border-radius: 4px;
    background-color: #fef0f0;
    border-color: #fde2e2;
    color: #f56c6c;
    li {
      margin-top: 5px;
    }
  }

  .btn-group {
    margin: 20px 0;
    display: flex;
    justify-content: center;
  }
</style>
